//
//  SlideOutAnimationController.swift
//  StoreSearch
//
//  Created by cygarm on 15/12/28.
//  Copyright © 2015年 cygarm. All rights reserved.
//

import Foundation
import UIKit

class SlideOutAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
	func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
		return 0.3
	}
	
	func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
		if let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey) {
			let duration = transitionDuration(transitionContext)
			let containerView = transitionContext.containerView()
			
			UIView.animateWithDuration(duration, animations: { () -> Void in
				fromView.center.y -= (containerView?.bounds.size.height)!
				fromView.transform = CGAffineTransformMakeScale(0.5, 0.5)
				}, completion: { (finished) -> Void in
					transitionContext.completeTransition(finished)
			})
		}
	}
}